package com.example.demo.payment.controller;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

@Slf4j
@RequestMapping
@RestController
public class PaymentController {

    @Value("${server.port}")
    int port;

    @GetMapping
    public String payment(@RequestParam("uid") String userId, @RequestParam("oid") String orderId,
                          HttpServletRequest request) {
        log.info("============ csrf-token:{}", request.getHeader("csrf-token"));
        return String.format("%s 创建的订单 %s 已成功支付，付款id %s, 付款时间 %s, 机器号：%d",
                userId, orderId, UUID.randomUUID(),
                LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
                port);
    }


}
